<template>
  <div class="all">
    <head-search></head-search>


    <div class="time_prograss">
      <div class="time_title">
        选择时间
      </div>
      <div class="c_flex">

        <show-time v-model="start_time" :is_min_date="false"></show-time>-
        <show-time v-model="end_time" :is_min_date="false"></show-time>
      </div>
    </div>
    <div @click="search" class="c_flex search">
      搜 索
    </div>
    <div class="time_prograss">
      <div class="time_title">
        加盟车流水
      </div>
      <van-list :offset="10" :immediate-check="false" v-model="loading" :finished="finished" finished-text="没有更多了"
        @load="onLoad" class="all">

        <div class="wrap_card">
          <div class="head fill" >
            <div>加盟商ID</div>
            <div>加盟商名称</div>
            <div>负责人</div>
            <div>预存金额</div>
            <div>消费金额</div>
          </div>
          <div class="fill item" v-for="(item,index) in list" :key="index">

          </div>
        </div>
      </van-list>
    </div>


  </div>
</template>

<script>
  import HeadSearch from '@/components/HeadSearch';
  import {
    HomeService
  } from '@/api'
  import ShowTime from '../../components/TimePicker/ShowTime.vue';
  export default {
    components: {
      HeadSearch,
      ShowTime,
    },
    mounted() {
      this.init();
    },
    data() {
      return {
        list: [],
        loading: false,
        finished: false,
        page: 1,
        limit: 10,

        start_time: new Date().toISOString().split('T')[0],
        end_time: new Date().toISOString().split('T')[0],
      }
    },
    methods: {
      init() {
        let _this = this;
        let data = {};
        if (_this.$store.state.search_id) {
          data.user_id = _this.$store.state.search_id;
        }
        Object.assign(this.$data, this.$options.data());
        this.onLoad();

      },
      search() {
        this.page = 1;
        this.onLoad();
      },
      onLoad() {
        // 异步更新数据
        this.loading = true; // loading,page,limit,list,finished
        // setTimeout 仅做示例，真实场景中一般为 ajax 请求
        HomeService.getResult({
          page: this.page,
          limit: this.limit,
          user_id: this.$store.state.search_id,
          start_date: this.start_time,
          end_date: this.end_time,
        }).then(res => {

          this.loading = false;
          if (res.data.data.length < this.limit) {

            this.list = this.list.concat(res.data.data)
            this.finished = true;
          } else {

            this.page++;
            this.list = this.list.concat(res.data.data)
          }


        })

      },
    }
  }
</script>

<style lang="less" scoped>
  .all {
    margin: 0;
    padding: 0;
    background-color: #f3f5f7;
    min-height: calc(93vh);
    box-sizing: border-box;


    .search {
      width: 640px;
      margin: 0px auto 15px;
      height: 80px;
      background-color: rgba(255, 255, 255, 1);
      border-radius: 8px;
      font-size: 28px;
    }

    .time_prograss {
      padding: 20px 24px;

      .time_title {
        margin: -10px 0 30px 0;
        color: rgba(51, 51, 51, 1);
        font-size: 24px;
      }

      .wrap_card {
        width: 702px;
        min-height: 800px;
        background-color: rgba(255, 255, 255, 1);
        border-radius: 16px;
        padding: 10px 32px;

        .head {
          color: rgba(51, 51, 51, 1);
          font-size: 20px;
        }

        .item {
          color: rgba(153, 153, 153, 1);
          font-size: 18px;
        }

        .fill {
          display: flex;
          flex-basis: 100px;
          justify-content: space-between;


          margin-top: 20px;
        }

      }



    }


  }
</style>